using System.IO.Ports;

namespace flowmeterserial
{
    public class SerialPortHelper
    {
        private SerialPort _serialPort;

        public void Connect(string portName, int baudRate)
        {
            _serialPort = new SerialPort(portName, baudRate);
            _serialPort.Open();
        }

        public void Disconnect()
        {
            if (_serialPort?.IsOpen ?? false)
            {
                _serialPort.Close();
            }
        }

        public void SendData(byte[] data)
        {
            _serialPort?.Write(data, 0, data.Length);
        }
    }
}